package com.sf.webside.controller;

import com.sf.webside.service.CmsCategoryService;
import entity.ResultVO;
import entity.StatusCode;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import util.GsonUtils;
import util.ResultVOUtil;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by tanjing on 2019/2/21.
 */
@RestController
@RequestMapping("/v1/cms/category")
@ResponseBody
public class CmsCategoryController extends BaseExceptionHandler{
    private Logger logger= LoggerFactory.getLogger(CmsCategoryController.class);
    @Autowired
    private CmsCategoryService cmsCategoryService;
    /**
     * 获取所有栏目
     */
    @GetMapping("/list/{languageType}")
    public Object list(HttpServletRequest request,@PathVariable String languageType){
        ResultVO checkoutToken=checkoutToken(request);
        if(checkoutToken.getCode()!=200) {
            return checkoutToken;
        }
        logger.info("list request {}",languageType);
        if(StringUtils.isBlank(languageType)){
            return ResultVOUtil.error(StatusCode.ERROR,"请输入语言");
        }
        ResultVO resultVO=cmsCategoryService.list(languageType);
        logger.info("list response "+ GsonUtils.getInstance().toJson(resultVO));
        return resultVO;
    }
}
